package com.hxzy.apsect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author wzm
 * @create 2024-03-12 16:21
 * project_name:JavaWeb2401
 * @Description
 */
/*@Component
@Aspect*/
@Slf4j
public class MyAspect {


    @Pointcut("@annotation(com.hxzy.annoation.MyLog)")
    public void pt() {
    }

    @Before("pt()")
    public void before(JoinPoint joinPoint){
        //获取目标方法的类名
        String name = joinPoint.getTarget().getClass().getName();
        log.info("11目标类名{}",name);

        //获取目标方法
        String methodName = joinPoint.getSignature().getName();
        log.info("111目标方法名{}",methodName);

        //获得方法的参数
        Object[] args = joinPoint.getArgs();
        log.info("11方法参数{}", Arrays.toString(args));


    }
    @After("pt()")
    public void after(){}

    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        //获取目标方法的类名
        String name = joinPoint.getTarget().getClass().getName();
        log.info("目标类名{}",name);

        //获取目标方法
        String methodName = joinPoint.getSignature().getName();
        log.info("目标方法名{}",methodName);

        //获得方法的参数
        Object[] args = joinPoint.getArgs();
        log.info("方法参数{}", Arrays.toString(args));

        //执行原始方法
        Object result = joinPoint.proceed();

        return  result;

    }

    @AfterReturning("pt()")
    public void afterReturning(){}

    @AfterThrowing("pt()")
    public void afterThrowing(){}

}